package ar.com.fiuba.service.impl;

import java.io.IOException;
import java.util.Map;

import ar.com.fiuba.SystemKeys;
import ar.com.fiuba.application.api.DataBaseLoader;
import ar.com.fiuba.application.api.DataSource;
import ar.com.fiuba.application.impl.FileDataSource;
import ar.com.fiuba.service.api.Service;

public class DBLoadService implements Service {

	private DataBaseLoader loader;

	public DBLoadService(DataBaseLoader loader) {
		this.loader = loader;
	}

	public void run(Map<String, String> parameters) {
		DataSource dataSource;
		try {
			dataSource = new FileDataSource(parameters.get(SystemKeys.DATA_BASE_LOADER_FILE_PATH));
		} catch (IOException e) {
			// Assuming existing file.
			e.printStackTrace();
			return;
		}
		loader.loadData(dataSource);
	}

}
